import 'package:flutter/material.dart';
import '../model/post.dart';
import '../demo/post_show.dart';

class ListViewPart extends StatelessWidget {
  /**
   * @params index 角标的索引值
   */
  Widget _itemBuild(BuildContext context, int index) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.all(8.0),
      child: Stack(
        children: <Widget>[
          Column(
            children: <Widget>[
              AspectRatio(
                aspectRatio: 16 / 9,
                child: Image.network(
                  postList[index].imageUrl,
                  fit: BoxFit.cover,
                ),
              ),
              SizedBox(height: 16.0),
              Text(
                postList[index].title,
                style: Theme.of(context).textTheme.title,
              ),
              Text(
                postList[index].author,
                style: Theme.of(context).textTheme.subhead,
              ),
              SizedBox(height: 16.0),
            ],
          ),
          Positioned.fill(
            child: Material(
              color: Colors.transparent,
              //InkWell设置渐幕效果区域
              child: InkWell(
                //渐幕颜色
                splashColor: Colors.white.withOpacity(0.3),
                //高亮颜色
                highlightColor: Colors.white.withOpacity(0.1),
                //点击回调
                onTap: () {
//                  debugPrint('tap.....click');
                  //跳转
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) {
                    return PostShow(post: postList[index]);
                  }));
                },
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemBuilder: _itemBuild,
      itemCount: postList.length,
    );
  }
}
